package com.test.webtest.service.impl;

import com.test.webtest.entity.PricePeriod;
import com.test.webtest.service.GetPriceService;
import org.springframework.stereotype.Service;

import java.time.LocalTime;
import java.util.Arrays;
import java.util.List;

/**
 * @Description GetPriceServiceImpl
 * @Author jiangzhenghao
 * @Date 2025-05-16  19:24
 */
@Service
public class GetPriceServiceImpl implements GetPriceService {

    // 预定义价格时段
    private static final List<PricePeriod> PRICE_TABLE = Arrays.asList(
            new PricePeriod(LocalTime.of(0,0), LocalTime.of(8,0), 0.38, 0.37),
            new PricePeriod(LocalTime.of(8,0), LocalTime.of(10,0), 0.82, 0.26),
            new PricePeriod(LocalTime.of(10,0), LocalTime.of(12,0), 1.28, 0.20),
            new PricePeriod(LocalTime.of(12,0), LocalTime.of(14,0), 0.80, 0.26),
            new PricePeriod(LocalTime.of(14,0), LocalTime.of(19,0), 1.28, 0.37),
            new PricePeriod(LocalTime.of(19,0), LocalTime.of(23,59,59), 0.88, 0.20)
            //全部换成Date类型

    );

    @Override
    public Double calculatePrice(LocalTime currentTime) {

        Double total = 0.0;
        for (PricePeriod period : PRICE_TABLE) {
            if (period.getBeginTime().compareTo(currentTime) <= 0 && period.getEndTime().compareTo(currentTime) >= 0) {
                total = period.getElectricPrice() + period.getWaiterPrice();
            }
        }
        return total;
    }


}
